package A;

import java.util.ArrayList;
import java.util.List;

public class Test_15 {
    public static void main(String[] args) {
        //将执行字符串中的内容封装到Dog对象中,sons属性为小狗的孩子们，
        // 字符串中逗号分隔的为多个孩子
        String str = "<Dog name='小白' color='白色'  sons='小黑,小花'/>";
        String name = str.substring(str.indexOf("name='") + "name='".length(), str.substring(str.indexOf("name='") + "name='".length()).indexOf("\'")+str.indexOf("name='") + "name='".length());
        String color = str.substring(str.indexOf("color='") + "color='".length(), str.substring(str.indexOf("color='") + "color='".length()).indexOf("\'")+str.indexOf("color='") + "color='".length());
        String sons = str.substring(str.indexOf("sons='") + "sons='".length(), str.substring(str.indexOf("sons='") + "sons='".length()).indexOf("\'")+str.indexOf("sons='") + "sons='".length());
        ArrayList<String> list = new ArrayList<>();
        String[] split = sons.split(",");
        for (String s : split) {
            list.add(s);
        }
        Dog d = new Dog(name, color, list);
        System.out.println(d);
    }
}
